<!--
 * @Author: wjc
 * @Date: 2025-09-28 09:02:43
 * @LastEditors: wjc
 * @LastEditTime: 2025-10-28 11:01:59
 * @Description: 
-->
<template>
  <EditorEmbed
    :entity="entity"
    :request-url="requestUrl"
    :message="message"
    @on-updated="onUpdate"
  />
</template>

<script setup lang="ts">
  import { api } from '#/api'
  import { useUserStore } from '#/stores/modules/user-store'

  defineOptions({
    name: 'MePassword',
  })

  const props = withDefaults(
    defineProps<{
      entity?: string
    }>(),
    {
      entity: '',
    }
  )

  const router = useRouter()
  const route = useRoute()
  const userStore = useUserStore()
  const message = '修改密码成功'

  const requestUrl = ref({
    edit: api[props.entity].password,
    update: api[props.entity].password,
  })

  const onUpdate = () => {
    userStore.changePassword().then(() => {
      router.push(`/login?redirect=${route.fullPath}`)
    })
  }
</script>
